<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
function status($status){
	if($status == 1){
		$str = "<span class='label label-success radius'>正常</span>";
	}else if($status == 0){
		$str = "<span class='label label-danger radius'>待审</span>";
	}else{
		$str = "<span class='label label-danger radius'>删除</span>";
	}
	return $str;
}

//是否为总店
function isMain($isMain){
	if($isMain == 1){
		$str = "<span class='label label-danger radius'>是</span>";
	}else{
		$str = "<span class='label label-success radius'>否</span>";
	}
	return $str;
}

/**
*@param $url
*@param int $type 0 get 1 post
*@param array $data
**/
function doCurl($url, $type=0, $data=[]){
	//初始化
	$ch = curl_init();
	//设置配置项
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	//post
	if($type==1){
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	}
	//执行并获取内容
	$output = curl_exec($ch);
	//释放$ch句柄
	curl_close($ch);
	return $output;
}

//商户入驻申请的文案
function bisRegister($status){

	if($status == 1){

		return '入驻申请成功';
	}else if ($status == 0) {

		return '审核通过后会发送邮件通知，请关注';
	}else if($status == 2){

		return '非常抱歉，您提交的申请审核不通过';
	}else{

		return '该申请无效，已被删除';
	}
	

}

function getSeCityName($path){
	if(empty($path)){
		return '';
	}
	if(preg_match('/,/', $path)){
		$cityPath = explode(',', $path);
		$cityId = $cityPath[1];
	}else{
		$cityId = $path;
	}

	$city = model('city')->get($cityId);
	return $city->name;
}

function countLocation($location_ids){
	if(preg_match('/,/',$location_ids)){
		$arr = explode(',',$location_ids);
		$location = model('BisLocation')->get(end($arr));
		return '【'.count($arr).'店通用】'.$location->name;
	}else {
		$location = model('BisLocation')->get($location_ids);
		return $location->name;
	}
}

//生成订单号
function setOrderSn(){
	list($t1, $t2) = explode(' ', microtime());
	$t3 = explode('.', $t1*10000);
	return $t2.$t3[0].(rand(10000,99999));
}

//弹窗口
function getMessege($status,$messege='',$action='index'){
	if($status == 1){
		$str = "<script>alert('".$messege."');self.location='".$action."';</script>";
	}else{
		$str = "<script>alert('".$messege."');window.history.back(-1);</script>";
	}

	return $str;
}